package com.lianniu.mgr.operMessage.controller;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.dict.model.DictionaryVo;
import com.lianniu.mgr.baseService.dict.service.IDictionaryService;
import com.lianniu.mgr.baseService.staff.service.IStaffService;
import com.lianniu.mgr.operMessage.service.IOperMessageService;
import com.lianniu.mgr.operMessage.vo.OperMessageConditionVo;
import com.lianniu.mgr.operMessage.vo.OperMessageVo;
import com.lianniu.mgr.orderManage.controller.OrderManageController;
import com.lianniu.mgr.orderManage.service.IOrderManageService;
import com.lianniu.mgr.orderManage.vo.OrderConditionVo;
import com.lianniu.mgr.orderManage.vo.OrderDetailVo;
import com.lianniu.mgr.orderManage.vo.OrderInfoVo;
import com.lianniu.mgr.orderManage.vo.ShipmentVo;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.util.ObjectUtil;
import com.lianniu.mgr.util.StringUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/rest/operMessage")
public class OperMessageRestController {

  private static final Logger logger = Logger.getLogger(OperMessageRestController.class);

  @Autowired
  IOperMessageService operMessageService;

  @RequestMapping(value="/operMessageList",method={RequestMethod.GET,RequestMethod.POST})
  public @ResponseBody BaseResult operMessageList(HttpServletRequest req, OperMessageConditionVo condition, PaginationInfo paginationInfo){
      logger.info("operMessageList begin");
      String createTimeFrom = req.getParameter("createTimeFrom");
      String createTimeTo = req.getParameter("createTimeTo");
      String type = req.getParameter("type");
      BaseResult operMessages = null;
      if(!"".equals(createTimeFrom) || !"".equals(createTimeTo)||!"".equals(type)){
          condition.setCreateTimeFrom(createTimeFrom);
          condition.setCreateTimeTo(createTimeTo);
          condition.setType(type);
      }
      logger.info("data:"+condition);
      operMessages = operMessageService.getOperMessageListForPage(condition, paginationInfo);
      logger.info("params[消息数据]"+JSON.toJSONString(operMessages));
      return operMessages;
  }
  
  @RequestMapping("/insertOperMessage")
  public @ResponseBody BaseResult insertOperMessage(HttpServletRequest request,OperMessageVo curVo){
      logger.info("OperMessageRestController insertOperMessage begin.");
      logger.info("OperMessageRestController insertOperMessage:"+ JSON.toJSONString(curVo));
      try {
          logger.info("insertOperMessage begin.");
          BaseResult baseResult = operMessageService.insertOperMessage(curVo);
          logger.info("insertOperMessage baseResult:" + JSON.toJSONString(baseResult));
          logger.info("insertOperMessage end.");
          return baseResult;

      } catch (Exception e) {
          logger.error("insertOperMessage error:"+e.getMessage());
          logger.info("OperMessageRestController insertOperMessage end.");
          return BaseResult.exception(e.getMessage());
      }
  }

    @RequestMapping("/modifyIsRead")
    public @ResponseBody BaseResult modifyIsRead(String id){
        logger.info(String.format("modifyIsRead %s id", id));
        BaseResult result = operMessageService.updateOperMessageRead(id);
        logger.info("modifyIsRead id result ： "+result);
        return result;
    }

    @RequestMapping(value = "/getOperTypeNum",method = {RequestMethod.GET, RequestMethod.POST})
    public @ResponseBody BaseResult getOperTypeNum(HttpServletRequest request) {
        logger.info("OperMessageRestController getOperTypeNum begin.");
        try {
            BaseResult baseResult = operMessageService.getOperTypeNum();
            logger.info("getOperTypeNum end.");
            logger.info("OperMessageRestController getOperTypeNum end.");
            return baseResult;
        } catch (Exception e) {
            logger.error("OperMessageRestController getOperTypeNum error:" + e.getMessage());
            logger.error("OperMessageRestController getOperTypeNum end.");
            return BaseResult.exception(e.getMessage());
        }
    }

}
